package top.myhdg.bijou.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.WindowManager;

import java.util.Calendar;

import top.myhdg.bijou.MainActivity;
import top.myhdg.bijou.R;
import top.myhdg.bijou.colorUi.util.SharedPreferencesMgr;

public class WelcomeActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏

        if (SharedPreferencesMgr.getBoolean("NightAuto", true)) {
            Calendar calendar = Calendar.getInstance();
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            if (hour < 6 || hour >= 19) {
                SharedPreferencesMgr.setInt("Theme", 1);
                setTheme(R.style.NightTheme);
            } else {
                SharedPreferencesMgr.setInt("Theme", 0);
                setTheme(R.style.DayTheme);
            }
        }
        //==========显示启动画面==========
        Integer time = 100;    //设置等待时间，单位为毫秒
        Handler handler = new Handler();
        //当计时结束时，跳转至主界面
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                WelcomeActivity.this.finish();
            }
        }, time);
        //==========显示启动画面==========

        //==========处理耗时任务==========
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        //跳转至 MainActivity
//                        Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
//                        startActivity(intent);
//                        //结束当前的 Activity
//                        WelcomeActivity.this.finish();
//                    }
//                });
//            }
//        }).start();
        //==========处理耗时任务==========
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return keyCode == KeyEvent.KEYCODE_BACK || super.onKeyDown(keyCode, event);
    }
}
